package weaver.interfaces.dfhj.duss.action;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.dfhj.duss.util.CalUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-10-28
 * @Description: 工程采购/施工合同审批流程
 * @ModifyLog:
 **/
/*
 *@Description: 工程采购/施工合同审批流程提交后更新平台预留与实际采购对比表采购合同总额字段
 *@Param:
 *@return:
 *@Author: Dusongsong
 *@Date: 2020/12/10
 */
public class WeaUpateHtjeToGcSsHtspAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog( "-----WeaUpateGcSsHtspHtjeAction-----" );
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        String pty_tableName = "uf_ptylhsjcgdbb";//平台预留和实际采购对比表
        try {
            rs.executeQuery( "select szxm,htje from " + tablename + " where requestid=?", requestid );
            rs.next();
            String szxm = Util.null2String( rs.getString( "szxm" ) );//所属项目
            String htje =  CalUtil.isZero(Util.null2String( rs.getString( "htje" )),2);//合同金额
            rs.executeQuery("select sum(cghtzey)AS cghtzeys,sum(czyua)AS czyuas,sum(nbptyl)AS nbptyls  from "+pty_tableName+" where xmbh=?",szxm);
            rs.next();
            String cghtzeys = CalUtil.isZero(Util.null2String(rs.getString( "cghtzeys" )),2);//2.	采购合同总额

            String czyuas = CalUtil.isZero(Util.null2String(rs.getString( "czyuas" )),2);// 超支（元）

            String nbptyls = CalUtil.isZero(Util.null2String(rs.getString( "nbptyls" )),2);//内包平台预留（元）

            if(!"0.00".equals( cghtzeys )){
                String cghtzey = CalUtil.fAdd(htje,cghtzeys);
                String czyua =  CalUtil.fSubtract(cghtzey,nbptyls);
                rs.executeUpdate("update "+pty_tableName+" set cghtzey=?,czyua=? where xmbh=?",cghtzey,czyua,szxm);
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
